<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>闭包思考题</title>
</head>
<body>
  <script>
    // 思考题 1：

    var name = 'The Window'
    var object = {
      name: 'My Object',
      getNameFunc: function () {
        return function () {
          return this.name
        }
      },
    }

    console.log(object.getNameFunc()())   // The Window   无闭包
    // var f = object.getNameFunc()
    // 类似于
    // var f = function () {
    //   return this.name
    // }
    // f()

    // 思考题 2：

    // var name = "The Window"
    // var object = {　　　　
    //     name: "My Object",
    //     getNameFunc: function() {
    //         var that = this
    //         return function() {
    //             return that.name
    //         }
    //     }
    // }
    // console.log(object.getNameFunc()())   // My Object   有闭包
    // 类似于
    // var f = object.getNameFunc()
    // var f = function () {
    //   return that.name
    // }
    // f()
  </script>
</body>
</html>